package threshold;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2023-03-12 22:14
 * @Version 1.0
 */
public class IsPalind {

     public boolean isPalindrome(String s) {
         StringBuffer sgood = new StringBuffer();
         int length = s.length();
         for (int i = 0; i <length ; i++) {
             char ch = s.charAt(i);
             if(Character.isLetterOrDigit(ch)){
                 sgood.append(Character.toLowerCase(ch));
             }
         }
         System.out.println(sgood.toString());
         StringBuffer good_rev = new StringBuffer(sgood).reverse();
         //StringBuffer good_rev1 = new StringBuffer(sgood.reverse());

         System.out.println(good_rev.toString());
         //System.out.println(good_rev1.toString());
         return sgood.toString().equals(good_rev.toString());
     }

     public boolean isPalindrome1(String s) {
        StringBuffer sgood = new StringBuffer();
        int length = s.length();
        for (int i = 0; i < length; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                sgood.append(Character.toLowerCase(ch));
            }
        }
        StringBuffer sgood_rev = new StringBuffer(sgood).reverse();
        return sgood.toString().equals(sgood_rev.toString());
    }

    public static void main(String[] args) {
         String  s = "race a car";

        IsPalind test = new IsPalind();
        System.out.println(test.isPalindrome(s));
    }
}
